/*    */ package cc.s2m.web.s2mBlog.util;
/*    */ 
/*    */ import java.util.Collection;
/*    */ import net.spy.memcached.MemcachedClient;
/*    */ import org.springframework.cache.Cache;
/*    */ import org.springframework.cache.support.AbstractCacheManager;
/*    */ 
/*    */ public class MemcacheCacheManager extends AbstractCacheManager
/*    */ {
/*    */   private Collection<Cache> caches;
/* 13 */   private MemcachedClient client = null;
/*    */ 
/*    */   public MemcacheCacheManager()
/*    */   {
/*    */   }
/*    */ 
/*    */   public MemcacheCacheManager(MemcachedClient client) {
/* 20 */     setClient(client);
/*    */   }
/*    */ 
/*    */   protected Collection<? extends Cache> loadCaches()
/*    */   {
/* 25 */     return this.caches;
/*    */   }
/*    */ 
/*    */   public void setCaches(Collection<Cache> caches) {
/* 29 */     this.caches = caches;
/*    */   }
/*    */ 
/*    */   public void setClient(MemcachedClient client) {
/* 33 */     this.client = client;
/* 34 */     updateCaches();
/*    */   }
/*    */ 
/*    */   public Cache getCache(String name) {
/* 38 */     checkState();
/*    */ 
/* 40 */     Cache cache = super.getCache(name);
/* 41 */     if (cache == null) {
/* 42 */       cache = new MemcacheCache(name, this.client);
/* 43 */       addCache(cache);
/*    */     }
/* 45 */     return cache;
/*    */   }
/*    */ 
/*    */   private void checkState() {
/* 49 */     if (this.client == null)
/* 50 */       throw new IllegalStateException("MemcacheClient must not be null.");
/*    */   }
/*    */ 
/*    */   private void updateCaches()
/*    */   {
/* 55 */     if (this.caches != null)
/* 56 */       for (Cache cache : this.caches)
/* 57 */         if ((cache instanceof MemcacheCache)) {
/* 58 */           MemcacheCache memcacheCache = (MemcacheCache)cache;
/* 59 */           memcacheCache.setClient(this.client);
/*    */         }
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\s2mBlog.zip
 * Qualified Name:     s2mBlog-3.0.0.WEB-INF.classes.cc.s2m.web.s2mBlog.util.MemcacheCacheManager
 * JD-Core Version:    0.6.1
 */